package com.dongdongshop.controller;

import com.dongdongshop.domain.AjaxResult;
import com.dongdongshop.domain.PageResult;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrandService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("brand")
public class BrandController {

    @DubboReference
    private BrandService brandService;

    @RequestMapping("brandShow")
    public String brandShow(){
        return "admin/brand";
    }

    @RequestMapping("brandList")
    @ResponseBody
    public AjaxResult brandList(@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "3")Integer pageSize){
        PageResult<TbBrand> list =brandService.brandList(pageNum,pageSize);
        return AjaxResult.ok().setData(list);
    }

    @RequestMapping("insertInfo")
    @ResponseBody
    public AjaxResult insertInfo(TbBrand tbBrand){
        brandService.insert(tbBrand);
        return AjaxResult.ok();
    }

    @RequestMapping("toUpdateById")
    @ResponseBody
    public AjaxResult toUpdateById(Long id){
        TbBrand tbBrand = brandService.toUpdateById(id);
        return AjaxResult.ok().setData(tbBrand);
    }

    @RequestMapping("updateInfo")
    @ResponseBody
    public AjaxResult updateInfo(TbBrand tbBrand){
        brandService.updateInfo(tbBrand);
        return AjaxResult.ok();
    }

    @RequestMapping("deleteInfo")
    @ResponseBody
    public AjaxResult deleteInfo(@RequestParam("ids[]")Integer[] ids){
        brandService.deleteInfo(ids);
        return AjaxResult.ok();
    }
}
